package io.renren.modules.member.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.member.entity.StandardCommEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

@Mapper
public interface StandardCommDao extends BaseMapper<StandardCommEntity> {

    @Select("<script>" +
            "SELECT " + StandardCommEntity.SQL_COLUMN + " FROM standard_comm m " +
            "WHERE " +
            "  sex = #{sex} AND type= #{type} " +
            " <if test=\"g1Achv != null \"> " +
            " <![CDATA[ AND m.g1_achv >= #{g1Achv} ]]>" +
            " </if>" +
            " <if test=\"g2Achv != null \"> " +
            " <![CDATA[ AND m.g2_achv >= #{g2Achv} ]]> " +
            " </if>" +
            " <if test=\"g3Achv != null \"> " +
            " <![CDATA[ AND m.g3_achv >= #{g3Achv} ]]> " +
            " </if>" +
            " <if test=\"g4Achv != null \"> " +
            " <![CDATA[ AND m.g4_achv >= #{g4Achv} ]]> " +
            " </if>" +
            " <if test=\"g5Achv != null \"> " +
            " <![CDATA[ AND m.g5_achv >= #{g5Achv} ]]> " +
            " </if>" +
            " <if test=\"g6Achv != null \"> " +
            " <![CDATA[ AND m.g6_achv >= #{g6Achv} ]]> " +
            " </if>" +
            " <if test=\"g7Achv != null \"> " +
            " <![CDATA[ AND m.g7_achv >= #{g7Achv} ]]> " +
            " </if>" +
            " <if test=\"g8Achv != null \"> " +
            " <![CDATA[ AND m.g8_achv >= #{g8Achv} ]]> " +
            " </if>" +
            " <if test=\"g9Achv != null \"> " +
            " <![CDATA[ AND m.g9_achv >= #{g9Achv} ]]> " +
            " </if>" +
            " <if test=\"g10Achv != null \"> " +
            " <![CDATA[ AND m.g10_achv >= #{g10Achv} ]]> " +
            " </if>" +
            " <if test=\"g11Achv != null \"> " +
            " <![CDATA[ AND m.g11_achv >= #{g11Achv} ]]> " +
            " </if>" +
            " <if test=\"g12Achv != null \"> " +
            " <![CDATA[ AND m.g12_achv >= #{g12Achv} ]]> " +
            " </if>" +
            " <if test=\"g13Achv != null \"> " +
            " <![CDATA[ AND m.g13_achv >= #{g13Achv} ]]> " +
            " </if>" +
            " ORDER BY score DESC LIMIT 1 " +
            "</script>")
    StandardCommEntity findByAchvAndSexAndTypeLess(Map<String, Object> params);

    @Select("<script>" +
            "SELECT " + StandardCommEntity.SQL_COLUMN + " FROM standard_comm m " +
            "WHERE " +
            " sex = #{sex} AND type= #{type} " +
            " <if test=\"g1Achv != null \"> " +
            " <![CDATA[ AND m.g1_achv <= #{g1Achv} ]]> " +
            " </if>" +
            " <if test=\"g2Achv != null \"> " +
            " <![CDATA[ AND m.g2_achv <= #{g2Achv} ]]> " +
            " </if>" +
            " <if test=\"g3Achv != null \"> " +
            " <![CDATA[ AND m.g3_achv <= #{g3Achv} ]]> " +
            " </if>" +
            " <if test=\"g4Achv != null \"> " +
            " <![CDATA[ AND m.g4_achv <= #{g4Achv} ]]> " +
            " </if>" +
            " <if test=\"g5Achv != null \"> " +
            " <![CDATA[ AND m.g5_achv <= #{g5Achv} ]]> " +
            " </if>" +
            " <if test=\"g6Achv != null \"> " +
            " <![CDATA[ AND m.g6_achv <= #{g6Achv} ]]> " +
            " </if>" +
            " <if test=\"g7Achv != null \"> " +
            " <![CDATA[ AND m.g7_achv <= #{g7Achv} ]]> " +
            " </if>" +
            " <if test=\"g8Achv != null \"> " +
            " <![CDATA[ AND m.g8_achv <= #{g8Achv} ]]> " +
            " </if>" +
            " <if test=\"g9Achv != null \"> " +
            " <![CDATA[ AND m.g9_achv <= #{g9Achv} ]]> " +
            " </if>" +
            " <if test=\"g10Achv != null \"> " +
            " <![CDATA[ AND m.g10_achv <= #{g10Achv} ]]> " +
            " </if>" +
            " <if test=\"g11Achv != null \"> " +
            " <![CDATA[ AND m.g11_achv <= #{g11Achv} ]]> " +
            " </if>" +
            " <if test=\"g12Achv != null \"> " +
            " <![CDATA[ AND m.g12_achv <= #{g12Achv} ]]> " +
            " </if>" +
            " <if test=\"g13Achv != null \"> " +
            " <![CDATA[ AND m.g13_achv <= #{g13Achv} ]]> " +
            " </if>" +
            " ORDER BY score DESC LIMIT 1 " +
            "</script>")
    StandardCommEntity findByAchvAndSexAndTypeMore(Map<String, Object> params);
}
